﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace QuanLyThuoc
{
    class Thuoc
    {
        string maThuoc;
        string tenThuoc;
        decimal giaBan;
        string congDung;
        string cachDung;
        string chongChiDinh;
        DateTime hanSuDung;
        string maNT;
        //NhomThuoc nhomThuoc;

        public string MaThuoc
        {
            get { return maThuoc; }
            set { maThuoc = value; }
        }
        public string TenThuoc
        {
            get { return tenThuoc; }
            set { tenThuoc = value; }
        }
        public decimal GiaBan
        {
            get { return giaBan; }
            set { giaBan = value; }
        }
        public string CongDung
        {
            get { return congDung; }
            set { congDung = value; }
        }
        
        public string CachDung
        {
            get { return cachDung; }
            set { cachDung = value; }
        }
        public string ChongChiDinh
        {
            get { return chongChiDinh; }
            set { chongChiDinh = value; }
        }
        public DateTime HanSuDung
        {
            get { return hanSuDung; }
            set { hanSuDung = value; }
        }
        public string MaNhomThuoc
        {
            get { return maNT; }
            set { maNT = value; }
        }
        
        public Thuoc()
        { }

        public Thuoc(string maThuoc, string tenThuoc, decimal giaBan, string congDung, string cachDung, string chongChiDinh, DateTime hanSuDung, string maNT)
        {
            this.maThuoc = maThuoc;
            this.tenThuoc = tenThuoc;
            this.giaBan = giaBan;
            this.congDung = congDung;
            this.cachDung = cachDung;
            this.chongChiDinh = chongChiDinh;
            this.hanSuDung = hanSuDung;
            this.maNT = maNT;
        }

        virtual public void NhapThuoc()
        {
            Console.Write("Nhap ma nhom thuoc: ");
            maNT = Console.ReadLine();
            Console.Write("Nhap ma thuoc: ");
            maThuoc = Console.ReadLine();
            Console.Write("Nhap ten thuoc: ");
            tenThuoc = Console.ReadLine();
            Console.Write("Nhap gia thuoc: ");
            giaBan = int.Parse(Console.ReadLine());
            Console.Write("Nhap cong dung thuoc: ");
            congDung = Console.ReadLine();
            Console.Write("Nhap cach dung: ");
            cachDung = Console.ReadLine();
            Console.Write("Nhap chong chi dinh cua thuoc: ");
            chongChiDinh = Console.ReadLine();
            Console.Write("Nhap han su dung: ");
            hanSuDung = DateTime.Parse(Console.ReadLine());
            
        }

        virtual public void XuatThuoc()
        {
            /*Console.Write("\nMa thuoc: {0}", maThuoc);//Console.Write("Ma thuoc: " + maThuoc);
            Console.Write("\tTen thuoc: {0}", tenThuoc);//Console.Write("Ten thuoc: " + tenThuoc);
            Console.Write("\tGia ban: {0}", giaBan);//Console.Write("Gia ban: " + giaBan);
            Console.Write("\tCong dung: {0}", congDung);//Console.Write("Cong dung: " + congDung);
            Console.Write("\tXuat xu: {0}", xuatXu);//Console.Write("Xuat xu: " + xuatXu);
            Console.Write("\tHuong dan su dung: {0}", cachDung);
            Console.Write("\tThan trong: {0}", thanTrong);
            Console.Write("\tHan su dung: {0}", hanSuDung);
            Console.Write("\tThuoc thuoc nhom thuoc: {0}", maNhomThuoc);*/

            //Console.Write("\nMa thuoc: " + maThuoc + "\tTen thuoc: " + tenThuoc + "\tGia ban: " + giaBan + "\tCong dung: " + congDung + "\tXuat xu: " + xuatXu + "\tHuong dan su dung: " + cachDung + "\tThan trong: " + thanTrong + "\t Han su dung: " + hanSuDung + "\tMa nhom thuoc: " + maThuoc);
            
            Console.WriteLine("-Ma thuoc: " + maThuoc);
            Console.WriteLine("-Ten thuoc: " + tenThuoc);
            Console.WriteLine("-Gia: " + giaBan);
            Console.WriteLine("-Cong dung: " + congDung);
            Console.WriteLine("-Cach dung: " + cachDung);
            Console.WriteLine("-Chong chi dinh: " + chongChiDinh);
            Console.WriteLine("-Han su dung: " + String.Format("{0:dd/MM/yyyy}", hanSuDung));
            //Console.Write("\t" + maNhomThuoc);
            //Console.Write(nhomThuoc.TenNhomThuoc);
            NhomThuoc nhom = DanhSachNhomThuoc.TimTheoMa(maNT);
            if (nhom != null)
                Console.WriteLine("-Nhom thuoc: " + nhom.TenNhomThuoc);
        }

        public virtual void ghiFile()
        {
            FileStream file = new FileStream("DSThuoc.txt", FileMode.Append);
            BinaryWriter bWriter = new BinaryWriter(file);
            bWriter.Write(maThuoc);
            bWriter.Write(tenThuoc);
            bWriter.Write(giaBan.ToString());
            bWriter.Write(congDung);
            bWriter.Write(cachDung);
            bWriter.Write(chongChiDinh);
            bWriter.Write(String.Format("{0:dd/MM/yyyy}", hanSuDung));
            bWriter.Write(maNT);
            bWriter.Close();
            file.Close();
        }
    }
}
